package ModelLayer;
import java.util.*;

public class ContractorContainer
{
    private ArrayList<Contractor>  contractorContainer;
    private static ContractorContainer instance;

    private ContractorContainer()
    {
        contractorContainer = new  ArrayList<Contractor>();
    }

    public static ContractorContainer getInstance(){
        if (instance == null){
            instance = new ContractorContainer();
        }
        return instance;
    }

    public Contractor findContractorByName(String name){
        Contractor pObject = null;
        int index = 0;
        boolean found = false;
        while(index < contractorContainer.size() && !found)
        {
            pObject = contractorContainer.get(index); 
            if(pObject.getName().equals(name))
            {
                found = true;
            }
            else{
                index++;
            }
        }
          if(found){
           return contractorContainer.get(index) ;
        }else{
            return  null;
        }
    }
    
    public Contractor findContractorById(int id){
        Contractor pObject = null;
        int index = 0;
        boolean found = false;
        while(index < contractorContainer.size() && !found)
        {
            pObject = contractorContainer.get(index); 
            if(pObject.getId() == id)
            {
                found = true;
            }
            else{
                index++;
            }
        }
      
          if(found){
           return contractorContainer.get(index) ;
        }else{
            return  null;
        }
    }
    

    public void addContractor(Contractor p){
        contractorContainer.add(p);
    }

    public void deleteContractor(Contractor p){
        if(contractorContainer.contains(p))
            contractorContainer.remove(p);
    }
}
